package com.aspose.cells;

import java.util.HashMap;
import java.util.Iterator;

class zcfb extends zcer {
   private HashMap e = new HashMap();

   zcfb(WorksheetCollection var1) {
      super(var1);
      Iterator var2 = var1.iterator();

      while(var2.hasNext()) {
         Worksheet var3 = (Worksheet)var2.next();
         this.e.put(var3.l(), var3.getName());
      }

   }

   void a(StringBuilder var1, byte[] var2, int var3) {
      var1.append(this.e());
   }

   void b(StringBuilder var1, byte[] var2, int var3) {
      var1.append(this.d());
   }

   String a(int var1) {
      return this.c();
   }

   private String c() {
      String var1 = this.g();
      boolean var2 = var1 != null;
      String var3 = this.h();
      String var4 = this.h();
      boolean var5 = var4 == null || com.aspose.cells.b.a.zv.b(var3, var4);
      if (zakq.b(var3)) {
         var2 = true;
      }

      if (!var5 && zakq.b(var4)) {
         var2 = true;
      }

      StringBuilder var6 = new StringBuilder();
      if (var2) {
         var6.append('\'');
      }

      if (var1 != null) {
         this.a(var6, var1);
      }

      if (var5) {
         if (var1 == null) {
            return var3;
         }

         var6.append(var3);
      } else {
         var6.append(var3);
         var6.append(':');
         var6.append(var4);
      }

      if (var2) {
         var6.append('\'');
      }

      return com.aspose.cells.b.a.zr.a(var6);
   }

   private void a(StringBuilder var1, String var2) {
      String var3 = var2.replace('/', '\\');
      int var4 = var3.lastIndexOf(92);
      if (var4 != -1) {
         var1.append(var3.substring(0, 0 + var4 + 1));
         var1.append('[');
         var1.append(var3.substring(var4 + 1));
      } else if (var3.length() > 2 && var3.charAt(1) == ':') {
         var1.append(var3.substring(0, 3));
         var1.append('[');
         var1.append(var3.substring(3));
      } else {
         var1.append('[');
         var1.append(var3);
      }

      var1.append(']');
   }

   private String d() {
      short var1 = com.aspose.cells.b.a.zc.b(this.d, this.c);
      this.c += 2;
      String var2 = this.f();
      if (var1 == -1) {
         return var2;
      } else {
         StringBuilder var3 = new StringBuilder();
         String var4 = (String)this.e.get(Integer.valueOf(var1));
         if (zakq.b(var4)) {
            var3.append('\'');
            var3.append(var4);
            var3.append('\'');
         } else {
            var3.append(var4);
         }

         var3.append('!');
         var3.append(var2);
         return com.aspose.cells.b.a.zr.a(var3);
      }
   }

   private String e() {
      String var1 = this.g();
      boolean var2 = var1 != null;
      if (this.d[this.c] == 0) {
         ++this.c;
         return this.d();
      } else {
         String var3 = zco.a(this.d, this.c);
         boolean var4 = this.d[this.c + 2] == 0;
         if (var4) {
            this.c += 3 + var3.length();
         } else {
            this.c += 3 + var3.length() + var3.length();
         }

         String var5 = this.f();
         StringBuilder var6 = new StringBuilder();
         if (!var2 && zakq.b(var3)) {
            var2 = true;
         }

         if (var2) {
            var6.append('\'');
         }

         this.a(var6, var1);
         var6.append(var3);
         var6.append('!');
         var6.append(var5);
         if (var2) {
            var6.append('\'');
         }

         return null;
      }
   }

   private String f() {
      String var1 = null;
      if (this.d[this.c] != 0) {
         var1 = Name.b((byte)((this.d[this.c] & 255) - 1));
      }

      ++this.c;
      boolean var2 = this.d[this.c + 2] == 0;
      String var3 = zco.a(this.d, this.c);
      this.c += 3;
      if (var3 != null) {
         this.c += var3.length() + (var2 ? 0 : var3.length());
      }

      if (var1 == null) {
         var1 = var3;
      }

      return var1;
   }

   private String g() {
      String var1 = null;
      if (this.d[this.c] != 1) {
         ++this.c;
         boolean var2 = this.d[this.c + 2] == 0;
         var1 = zco.a(this.d, this.c);
         this.c += 3;
         if (var1 != null) {
            this.c += var1.length() + (var2 ? 0 : var1.length());
         }

         this.c += 4 + var1.length() * 2;
         var1 = zbqg.a(var1, this.b.n());
      } else {
         this.c += 2;
      }

      return var1;
   }

   private String h() {
      String var1 = "";
      switch(this.d[this.c]) {
      case 0:
         var1 = (String)this.e.get(Integer.valueOf(com.aspose.cells.b.a.zc.b(this.d, this.c + 1)));
         this.c += 2;
         break;
      case 1:
         boolean var2 = this.d[this.c + 2] == 0;
         var1 = zco.a(this.d, this.c);
         this.c += 3;
         if (var1 != null) {
            this.c += var1.length() + (var2 ? 0 : var1.length());
         }
         break;
      case 2:
         var1 = null;
         break;
      case 3:
         var1 = "#REF";
      }

      ++this.c;
      return var1;
   }
}
